<?php
/*
 * Created on 2007-9-21
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class database {
	//
	private $host;
	private $user;
	private $pwd;
	private $name;
	private $connection;
		
	//__get()
	function __get($property_name){  
		if(isset($this->$property_name)) { 
			return($this->$property_name); 
		}else {
			return(NULL); 
		}
	}
	
	//__set()
	function __set($property_name, $value) { 
		$this->$property_name = $value; 
	}
		
	//__construct
	function __construct(){
		$this->host		= sys_conf::$DBHOST;
		$this->user		= sys_conf::$DBUSER;
		$this->pwd		= sys_conf::$DBPWD;
		$this->name		= sys_conf::$DBNAME;
		
		$this->connection = mysql_connect ($this->host,$this->user,$this->pwd);
		mysql_query("SET NAMES 'gbk'");
		mysql_select_db($this->name, $this->connection);
	}
	
	//__destruct
	function __destruct(){
		//mysql_close($this->connection);
	}
	
	//execute
	function execute($sql){
		return mysql_query($sql);
	}
	
	//query
	function query($sql){
		$result_array=array();//
		$i=0;
		$query_result=mysql_query($sql,$this->connection);
		//echo $sql;
		while($row=mysql_fetch_object($query_result)){
			$result_array[$i++]=$row;
		}
		return $result_array;
	}
	
	function listTable(){
		$tables = mysql_list_tables(sys_conf::$DBNAME);
		$table = array();
		while ($row = mysql_fetch_row($tables)) {
	        $table[] = $row[0];
	    }
	    return $table;
	}
}
?>
